package corej.course.net;

import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class TCPServer1 {
    
    public static void main(String[] args) throws Exception {
        //1.创建ServerSocket
        ServerSocket ss = new ServerSocket(9000);
        //2.开始侦听
        Socket s = ss.accept();

        //3.得到Socket的输出流
        OutputStream os = s.getOutputStream();

        //4.封装打印
        PrintWriter out = new PrintWriter(os);
        for (int i = 1; i <= 20; i++) {
            out.println(i + "  HelloWorld");
            out.flush();
            Thread.sleep(1000);
        }

        //5.关闭Socket
        s.close();

        //6.关闭ServerSocket
        ss.close();
    }
}
